#!/bin/bash

# 🔥 支付宝SDK真机测试恢复脚本
# 作用：恢复tobias.podspec原始配置，支持真机上的支付宝支付功能

echo "=================================="
echo "🔄 恢复支付宝SDK真机配置"
echo "=================================="
echo ""

# 查找tobias路径
TOBIAS_PATH=$(find ~/.pub-cache/hosted -name "tobias-*" -type d | head -n 1)

if [ -z "$TOBIAS_PATH" ]; then
  echo "❌ 未找到tobias插件"
  exit 1
fi

PODSPEC_PATH="$TOBIAS_PATH/ios/tobias.podspec"
BACKUP_PATH="${PODSPEC_PATH}.backup"

if [ ! -f "$BACKUP_PATH" ]; then
  echo "❌ 未找到备份文件"
  echo "路径: $BACKUP_PATH"
  echo ""
  echo "如果从未运行过修复脚本，说明配置已是原始状态"
  exit 1
fi

echo "📦 找到备份文件: $BACKUP_PATH"
echo ""
echo "🔄 恢复原始配置..."

# 恢复原文件
cp "$BACKUP_PATH" "$PODSPEC_PATH"

echo "✅ tobias.podspec 恢复完成"
echo ""
echo "📋 后续步骤:"
echo "  1. cd ios && pod install"
echo "  2. flutter clean"
echo "  3. 连接iPhone真机"
echo "  4. flutter run"
echo ""
echo "ℹ️  提示:"
echo "  - 真机上支持完整的支付宝支付功能"
echo "  - 模拟器将无法编译（AlipaySDK不支持模拟器）"
echo "  - 需要模拟器调试时，重新运行: ./fix_alipay_simulator.sh"
echo ""
echo "=================================="
echo "✅ 恢复完成！"
echo "=================================="

